// import $ from 'jquery'
export default {
  name: 'viewIndex',
  data () {
    return {
      baseSiteNums: 0,
      cellNums: 0,
      upocts: 0,
      high_load_num: 0,
      radio_use_rate: 0,
      volte_voice_traffic: 0,

      integrity_cell_tdd: 0,
      ratio_online_tdd: 0,
      inandoutdoor_cell_traffic_ratio: 0,

      complain_num: 0,
      distribute_num_sum: 0,
      complain_repeat_rate: 0,

      high_load_ratio_lte: 0,
      high_interfer_cell_ratio_tdd: 0,
      mr_coverage_rate: 0
    }
  },
  components: {
  },
  methods: {

    getBasePath () {
      let obj = window.location
      let contextPath = obj.pathname.split('/')[1]
      let basePath = obj.protocol + '//' + obj.host + '/' + contextPath + '/'
      return basePath
    },

    getApiPath () {
      let obj = window.location
      return obj.protocol + '//' + obj.host + '/'
    },
// 页面跳转
    index_page_query (yemian) {
      // window.location.href = getBasePath()  + yemian;
    },
    setBaseVal (res) {
      this.baseSiteNums = this.toThousands(res[4].site_num_lte)
      // $('#baseSiteNums').html(this.toThousands(res[4].site_num_lte))// 基站数
      this.cellNums = this.toThousands(res[4].cell_num_lte)// 小区数
      this.upocts = this.toThousands(res[0].upoct)// 总流量
      this.innetwork_rate = res[3].innetwork_rate// 综合在网率
      this.available_rate = res[3].available_rate// 综合可用率
      this.withdrawal_rate_lte = res[3].withdrawal_rate_lte// 4G退服率
      this.aggregate_demand_num = this.toThousands(res[3].aggregate_demand_num)// 总需求数量
      this.aggregate_completed_num = this.toThousands(res[3].aggregate_completed_num)// 总需求完成数量
      this.aggregate_demand_succ_rate = res[3].aggregate_demand_succ_rate// 总需求完成率
      this.complain_repeat_rate = parseFloat(res[5].complain_repeat_rate).toFixed(2)// 基础通信重复投诉率
      this.high_load_ratio_lte = res[3].high_load_ratio_lte// 4G高负荷小区占比
      this.high_interfer_cell_ratio_tdd = res[3].high_interfer_cell_ratio_tdd// 高干扰小区占比
      this.mr_coverage_rate = parseFloat(res[8].mr_coverage_rate).toFixed(2)// MR覆盖率
      this.complain_num = this.toThousands(res[1].complain_num_sum)// 日总投诉量
      this.distribute_num_sum = this.toThousands(parseInt(res[1].distribute_num_crm_sum) + parseInt(res[1].distribute_num_eoms_sum))// 基础通信工单量-->今日已派发量
      // network2
      this.radio_use_rate = parseFloat(res[0].radio_use_rate).toFixed(2)// MR覆盖率
      this.volte_voice_traffic = this.toThousands(res[0].volte_voice_traffic)// 日总投诉量
      this.high_load_num = this.toThousands(res[0].high_load_num)// 高负荷小区数

      // 维护模块
      this.inandoutdoor_cell_traffic_ratio = parseFloat(res[5].inandoutdoor_cell_traffic_ratio).toFixed(2)// 4G室分流量承载比(%)
      this.integrity_cell_tdd = parseFloat(res[6].integrity_cell).toFixed(2)// TDD小区完好度(%)
      this.ratio_online_tdd = parseFloat(res[7].ratio_online_tdd).toFixed(2)// TDD无线设备在网率(%)
    },

    getWideData (param, reqUrl) {
      this.$server.index(
        param, reqUrl
      ).then(res => {
        console.log(res)
        if (res.length > 2) {
          try {
            this.setBaseVal(res)
          } catch (e) {
            console.log(e)
          }
        } else {
          alert('数据查询失败')
        }
      })
    },


    pageLoad: function (geography, shiduan, geo_dim, city, area) {
      this.timeChart(shiduan, geo_dim, city, area)
    },
    timeChart: function (shiduan, geo_dim, city, area) {
      let param = {
        geo_dim: geo_dim,
        city: city,
        time_dim: shiduan,
        area: area,
        num: 1
      }
      this.getWideData(param, 'index/timeChart')
    },

    // 新增千位符
    toThousands (num) {
      let num1 = (num || 0).toString()
      let result = ''
      let numTmp = num1
      let isCludes = false
      if (num1.includes('.')) {
        num1 = num1.split('.')[0]
        isCludes = true
      }
      while (num1.length > 3) {
        result = ',' + num1.slice(-3) + result
        num1 = num1.slice(0, num1.length - 3)
      }
      if (num1) { result = num1 + result }
      if (isCludes) {
        result = result + '.' + numTmp.split('.')[1]
      }
      return result
    }

  },
  mounted () {
  },
  created: function () {
    // this.$parent.setHeader(false) //  可以实现
    this.$emit('setHeader', false)
    this.pageLoad('true', 'D', '省', '全量小区', '全量小区')
  }
}
